package com.a.ims.util;

/**
 *
 * @author QiuShiju
 * @date 2024/12/24
 * @desc R类是统一与前端交互的JSON类
 *
 * Result
 * Return
 * Resource
 * --------------
 * JSON交互的类一般有三个信息
 * code 状态码,视公司情况而定,假设 2000成功4000超时 5000是 没有权限 6000令牌无效...
 * msg 信息,给前端解释信息
 * data , 数据给前端展示
 */
public class R<T> {

    private int code;
    private String msg;
    private T data;

    public static <T> R<T>  ok(){
        R<T> r = new R<T>( );
        r.setCode(200);
        r.setMsg("成功");
        return r;
    }

    public static <T> R<T>  ok(T t){
        R<T> r = ok();
        r.setData(t);
        return r;
    }

    public static <T> R<T>  error(String msg){
        R<T> r = new R<>( );
        r.setCode(400);
        r.setMsg(msg);
        return r;
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
